<template>
    <div class="allbuju">
        <Top/>
           <div> 
              <hr>
              <div>    <el-input v-model="input4" class="w-50 m-2" placeholder="输入课程名称搜索">
        <template #prefix>
          <el-icon class="el-input__icon"><search /></el-icon>
        </template>
      </el-input></div>
              <span>所有活动</span>
         
          
           
 

		<div class="commodity">
			<!--// 左侧导航内容 -->
			<div class="leftNav">
				<ul>
					<li v-for="(item, index) in shopList" :key="index" :class="{ typeStyle: index === currentIndex }"
						@click="onClickNav(index)">
						<span class="leftTit">{{ item.shopName }}</span>
					</li>
				</ul>
			</div>
			<!--// 右侧商品内容 -->
			<div class="rightContant">
				<ul ref="shopContant">
					<li class="eventList" v-for="(item, index) in shopList" :key="index">
						<div class="rightTtitle">{{ item.shopName }}</div>
						<ul>
							<li class="gather" v-for="(item, index) in item.shopGather" :key="index">
								<div>
									<img :src="item.shopImgUrl" />
								</div>
								<div class="distance">
									<div class="shopName">🔈{{ item.shopName }}</div>
									<div class="saleGood">
										<span>⌚{{ item.monthNum }}</span>
										&nbsp;&nbsp;<span> {{ item.reputation }}</span>
									</div>
								
								</div>
							</li>
							<div style="height:1px"></div>
						</ul>
					</li>
				</ul>
			</div>
		</div>
	</div>
	 <!-- 底部 -->
     <div id="footer">
            <div class="foot"  @click="shequgonggongfuwu">
                    <div class="topright"> 
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-shouye"></use>
                        </svg>
                    </div>
                    <span >首页</span>
                </div>
				
                <div class="foot" @click="jiaoyukecheng">
                    <div class="topright"> 
                         <el-icon size="36" class="el-input__icon" ><Star style="width: 1em; height: 1em; margin-right: 8px" /></el-icon>
      
                    </div>
                   活动
                </div>
                <div class="foot" @click="gerenxinxi">
                    <div class="topright"> 
                   <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-31wode"></use>
                        </svg> </div>
                    <span>我的</span>
                </div>
        </div>
  

    </div>
</template>


<script >
import { Search } from '@element-plus/icons-vue'
import Top from '@/components/Top.vue'
import BScroll from "better-scroll"; //引入BScroll插件
import { ArrowDown, Document } from "@element-plus/icons-vue"
export default {
  name: 'jiaoyukecheng',
  components: {
    Top, 
  }, 


data(){
  return{
 

 	scrollY: 0, // 右侧滑动的时候距离顶部的值
				rightSide: [], // 所有右侧分类li的top组成的数组  (列表第一次显示后就不再变化)
        	//模拟的商品数据
				shopList: [{
						shopName: "全部",
						shopGather: [	{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "围棋-朗观下棋活动",
								monthNum: "教育慧邻云课堂" ,
								reputation:"2人在学" ,
								price: 56.85,
							},
							{
									shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "孟庆鸿-家庭教育",
								monthNum:"教育慧邻云课堂" ,
								reputation:"0人在学" ,
								price: 56.85,
							},	{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "三长五员工作专班培训",
								monthNum:"小区点长培训" ,
								reputation: "122222人在学",
								price: 56.85,
							},
							{
									shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"教育慧邻云课堂"  ,
								reputation:"2022年12月30日" ,
								price: 56.85,
							},
						{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"教育慧邻云课堂"  ,
								reputation: "17人在学",
								price: 56.85,
							},
							{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"教育慧邻云课堂"  ,
								reputation: "17人在学",
								price: 56.85,
							},
						
						]
					},
					{
						shopName: "在线自学",
						shopGather: [	{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "李正华-书法",
								monthNum:"教育慧邻云课堂" ,
								reputation: "5人在学",
								price: 56.85,
							},
						{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "李正华-书法",
								monthNum:"教育慧邻云课堂" ,
								reputation: "5人在学",
								price: 56.85,
							},
					{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "赵红-画画",
								monthNum:"教育慧邻云课堂" ,
								reputation: "5人在学",
								price: 56.85,
							},
              {
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "民族舞-高浩",
								monthNum:"教育慧邻云课堂" ,
								reputation: "5人在学",
								price: 56.85,
							},
              {
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "模特-赵宏伟",
								monthNum:"教育慧邻云课堂" ,
								reputation: "5人在学",
								price: 56.85,
							},
              {
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "书法-林明华",
								monthNum:"教育慧邻云课堂" ,
								reputation: "5人在学",
								price: 56.85,
							},
              {
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "太极拳-李洪刚",
								monthNum:"教育慧邻云课堂" ,
								reputation: "5人在学",
								price: 56.85,
							},
					
					
						]
					},	{
						shopName: "就业技能",
						shopGather: [{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
              {
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						
						]
					},
          	{
						shopName: "高中教育",
						shopGather: [{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
              {
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						
						]
					},
					{
						shopName: "初中教育",
						shopGather: [{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
              {
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
						
						]
					},
					{
						shopName: "小学教育",
						shopGather: [	{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},{
								
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "初级农艺工",
								monthNum:"农艺技师" ,
								reputation: "4人在学",
								price: 56.85,
							},
							{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
									shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
									shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
								shopImgUrl: require("@/assets/index/a6efce1b9d16fdfad1ef3ab4ebf7655e95ee7b68.png"),
								shopName: "珠海唐家湾举行粤港澳见面交流会",
								monthNum:"2022年1月11日",
								reputation: 90,
								price: 23.9,
							},
							{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
									shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
									shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
								{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
									shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
						{
								shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
							{
									shopImgUrl: require("@/assets/index/index.jpg"),
								shopName: "珠海星湾社区开展“消防安全护校园”活动",
								monthNum:"2022年12月30日" ,
								reputation: 99,
								price: 56.85,
							},
						]
					}
				]
 }
 },

	mounted() {
			this.initializeRoll(); //滑动初始化方法
			this.initializeOwn(); //初始化rightSide方法
		},
    	//计算属性
		computed: {
			// 计算出当前分类的下标
			currentIndex() {
				const {
					scrollY,
					rightSide
				} = this; //拿到每次滑动的值以及每一个分类的下标值
				console.log('滚动的值及每一个分类的下标值...', this)
				//findIndex() 方法返回传入一个测试条件（函数）符合条件的数组第一个元素位置
				//获取数组rightSide中每一个下标值并筛选条件返回第一个元素索引位置
				const index = rightSide.findIndex((top, index) => {
					// scrollY>=当前top && scrollY<下一个top
					return scrollY >= top && scrollY < rightSide[index + 1];
				});
				// 返回结果
				return index;
			}
		},
		methods: {
			 
        jiaoyukecheng:function(){
            this.$router.replace('/jiaoyukecheng')
        },
		 shequgonggongfuwu:function(){
            this.$router.replace('/shequgonggongfuwu')
        },
		 gerenxinxi:function(){
            this.$router.replace('/gerenxinxi')
        },
			// 初始化滚动
			initializeRoll() {
				// new一个类的实例，前提必须确保父元素和子元素的内容已经正确渲染了，不然不会生效
				new BScroll(".leftNav", {
					click: true
				});
				// 组件实例上挂属性
				this.foodsScroll = new BScroll(".rightContant", {
					probeType: 2, // 因为惯性滑动不会触发
					click: true
				});

				// 给右侧列表绑定scroll监听
				this.foodsScroll.on("scroll", ({
					x,
					y
				}) => {
					this.scrollY = Math.abs(y);
				});
				// 给右侧列表绑定scroll结束的监听
				this.foodsScroll.on("scrollEnd", ({
					x,
					y
				}) => {
					console.log("操作结束的下标值" + x, y);
					this.scrollY = Math.abs(y);
				});
			},
			// 初始化rightSide
			initializeOwn() {
				// 初始化rightSide
				const rightSide = [];
				let top = 0;
				rightSide.push(top);
				// 找到所有分类下的li
				const lis = this.$refs.shopContant.getElementsByClassName("eventList"); //获取dom元素lii（eventList），对其进行操作
				// slice() 方法返回一个新的数组对象
				Array.prototype.slice.call(lis).forEach(li => {
					top += li.clientHeight; //相当于top = top + li.clientHeight
					rightSide.push(top);
				});

				//更新数据
				this.rightSide = rightSide;
				console.log("每一个分类的下标" + rightSide);
			},
			//左侧点击事件
			onClickNav(index) {
				console.log(index);
				//拿到目标位置的scrollY，点击左侧导航，右侧列表滑动到对应的位置
				const scrollY = this.rightSide[index];
				// 点击的分类成为当前分类，索引当前选中的导航标题
				this.scrollY = scrollY;
				// 平滑滑动右侧列表
				this.foodsScroll.scrollTo(0, -scrollY, 1000);
			}
		}
	};


	
		
	
			

</script>
<script setup >
import { ref } from 'vue'
import  {Star} from '@element-plus/icons-vue'
const input = ref('')

</script>

<style>
.commodity {
		/* 最大的盒子样式 */
		display: flex;
		 height: 664px;
		top: 300px;
		bottom: 0px;
		width: 390px;
		background: #fff;
		overflow: hidden;
	}


	.leftNav {
		/* 左侧大盒子的整体样式 */
		width: 100px;
		background: rgb(248, 248, 248);
	}

	.typeStyle {
		/* 左侧导航选中的样式 */
		background: #fff;
		font-weight: bold;
		display: flex;
		align-items: center;
		color: rgb(255, 94, 121);
		justify-content: center;
		border-left: 0px solid rgb(255, 94, 121);
	}

	.leftTit {
		/* 左侧导航标题默认样式 */
		display: flex;
		height: 40px;
		justify-content: center;
		font-size: 12px;
		align-items: center;
	}

	.rightContant {
		/* 右侧大盒子的整体样式 */
		flex: 10;
	}

	.rightTtitle {
		/* 右侧标题样式 */
		padding-left: 1px;
		height: 26px;
		line-height: 26px;
		font-size: 12px;
		font-weight: bold;
		color: rgb(147, 153, 159);
		background: rgb(248, 248, 248);
		margin: 0;
	}

	.gather {
		/* 右侧每一个活动的样式 */
		display: flex;
		margin: 1px;
		display: flex;
		align-items: center;
	}

	.distance {
		/* 右侧图片与描述间距 */
		padding-left: 6px;
	}

	.gather img {
		/* 右侧图片样式 */
		width: 50px;
		height: 60px;
		
	}

	:last-child {list-style: none;
		/* 点击左侧导航右侧内容与左边对齐 */
		margin-bottom: 0;
	}

	.shopName {
		/* 右侧活动标题字体大小 */
		font-size: 14px;
	}

	.saleGood {
		/* 右侧时间样式 */
		font-size: 10px;
		color: rgb(147, 153, 159);
		padding: 4px 0px;
	}

	.saleGood span:first-child {
		/* 公式样式 */
		padding-right: 19px;
	}



#footer{
    width: 100%;
    height: 60px;
    background: rgb(216, 239, 216);
    display: flex;               
    justify-content: space-between;
    align-items: center;
}
.foot{
    padding: 5px;
}
span{
    margin-left: 9px;
}
</style>